//
//  PrologueViewController.m
//  dangdang
//
//  Created by air on 16/3/7.
//  Copyright © 2016年 luweijie. All rights reserved.
//

#import "PrologueViewController.h"
#import "GuideViewController.h"

@interface PrologueViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView * myScrollView;

@end

@implementation PrologueViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSArray *arr=[NSArray arrayWithObjects:@"引导页1.png", @"引导页2.png", @"引导页3.png", @"引导页4.png", nil];
    
    _myScrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [_myScrollView setPagingEnabled:YES];
    [_myScrollView setDelegate:self];
    _myScrollView.showsVerticalScrollIndicator = NO;
    _myScrollView.showsHorizontalScrollIndicator = NO;
    
    for (int i = 0; i < arr.count; i ++) {
        UIImageView *img=[[UIImageView alloc] initWithFrame:CGRectMake(i * [UIScreen mainScreen].bounds.size.width, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
        img.backgroundColor = [UIColor clearColor];
        img.userInteractionEnabled = YES;
        img.image=[UIImage imageNamed:arr[i]];
        
        if (i == arr.count - 1) {
            UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(self.view.center.x - 60, self.view.bounds.size.height - 65, 120, 40)];
            button.backgroundColor = [UIColor clearColor];
            [button addTarget:self action:@selector(stopScroll) forControlEvents:UIControlEventTouchUpInside];
            [img addSubview:button];
        }
        
        [_myScrollView addSubview:img];
    }
    
    _myScrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width * arr.count, 0);
    [_myScrollView scrollRectToVisible:CGRectMake([UIScreen mainScreen].bounds.size.width, 0, [UIScreen mainScreen].bounds.size.width, _myScrollView.frame.size.height) animated:NO];
    _myScrollView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:_myScrollView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)stopScroll{
    GuideViewController * guideboardVC = [[GuideViewController alloc] init];
//    UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:guideboardVC];
    [self presentViewController:guideboardVC animated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
